package cn.tedu.project.oa.assetRequisition.service.impl;

import cn.tedu.project.oa.assetRequisition.mapper.AssetRequisitionMapper;
import cn.tedu.project.oa.assetRequisition.pojo.dto.AssetRequisitionQuery;
import cn.tedu.project.oa.assetRequisition.pojo.dto.AssetRequisitionSaveParam;
import cn.tedu.project.oa.assetRequisition.pojo.entity.AssetRequisition;
import cn.tedu.project.oa.assetRequisition.pojo.vo.AssetRequisitionVO;
import cn.tedu.project.oa.assetRequisition.service.AssetRequisitionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class AssetRequisitionServiceImpl implements AssetRequisitionService {

    @Autowired
    AssetRequisitionMapper assetRequisitionMapper;

    @Override
    public void saveRequisition(AssetRequisitionSaveParam assetRequisitionSaveParam) {
        log.debug("保存领用资产申请单业务：assetRequisitionSaveParam={}",assetRequisitionSaveParam);

        AssetRequisition assetRequisition = new AssetRequisition();
        BeanUtils.copyProperties(assetRequisitionSaveParam,assetRequisition);

        if(assetRequisition.getId()==null){
            assetRequisition.setApplicationTime(new Date());
            assetRequisition.setStatus(10);
            assetRequisitionMapper.insert(assetRequisition);
        }else {
            assetRequisition.setUpdateTime(new Date());
            assetRequisitionMapper.update(assetRequisition);
        }

    }

    @Override
    public List<AssetRequisitionVO> selectRequisition(AssetRequisitionQuery assetRequisitionQuery) {
        log.debug("查询领用资产列表业务:assetRequisitionQuery={}",assetRequisitionQuery);

        List<AssetRequisitionVO> list = assetRequisitionMapper.selectList(assetRequisitionQuery);

        return list;
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除领用申请业务:id={}",id);

        assetRequisitionMapper.deleteById(id);
    }

    @Override
    public void updateStatusById(AssetRequisitionSaveParam assetRequisitionSaveParam) {
        log.debug("更新审批状态业务:assetRequisitionSaveParam={}",assetRequisitionSaveParam);


        assetRequisitionMapper.updateStatusById(assetRequisitionSaveParam);
    }

}
